//@include transactions

function main( json, ui, hh ) {

  return createTransaction( json );
}

function createTransaction( o ) {
 
  
  //o.copyTo( t );
   
  //t.date = new Date();
  
  EntityManager.execTransaction( function() {
	  
	  var t = new TransactionEntity();
	  
	  t.userId = "test";
    
	  var result = EntityManager.findSingle( "select t from TransactionEntity t where t.userId=:userId",  toMap({ userId:t.userId })) ;
    
	  if( result==null ) {
		  EntityManager.createTransaction( t );
		  
		  Log.info( "entity " + t + " inserted " );
	  }
	  else {
		  Log.info( "entity " + t + " skipped " );
		  
	  }
    
	  
	  var t2 = new TransactionEntity();
	  
	  t2.userId = "test2";

	  var result = EntityManager.findSingle( "select t from TransactionEntity t where t.userId=:userId",  toMap({ userId:t2.userId })) ;
	    
	  if( result==null ) {
		  EntityManager.createTransaction( t2 );
		  
		  Log.info( "entity " + t2 + " inserted " );
	  }
	  else {
		  Log.info( "entity " + t2 + " skipped " );
		  
	  }
    
    return true;
  } );
  
  
  return getAllTransactions();
  
}